/*
    Dark GDK Library, which is to make management of the Darkgdk graphic engine easier
    to use, as the built in function can be inefficient, or hard to use, or leak,
    which is compensated by this library.
*/
#ifndef DARK_HPP
#define DARK_HPP

#include "DarkGDK.h"
#include "BJ.h"

class DarkImage
{
    public :
        
        DarkImage
        (
            char *iPImageLocation,
            int   iImageId
        )
        {
            _imageId = iImageId;
            _imageLocation = iPImageLocation;
            dbLoadImage ( iPImageLocation, iImageId );
        }
        virtual ~DarkImage
        (
            void
        )
        {
            dbDeleteImage ( _imageId );
        }
        string image_location
        (
        )
        {
            return _imageLocation;
        }
        int image_id
        (
        )
        {
            return _imageId;
        }
    protected :
        string _imageLocation;
        int  _imageId;
};

class DarkBackgroundImage : public DarkImage
{
    public :
        
        DarkBackgroundImage
        (
            char *iPImageLocation,
            int   iSpriteId,
            int   iImageId
        ) : DarkImage(iPImageLocation, iImageId)
        {
            _spriteId = iSpriteId;

            dbSprite
            (
                iSpriteId,
                0,          // X Coordinate of the top left hand corner
                0,          // Y Coordinate of the top left hand corner
                iImageId
            );
        }

        ~DarkBackgroundImage
        (
            void
        )
        {
            dbDeleteSprite(_spriteId);
        }
        
    protected :
        
        int _spriteId;
};

class Dark
{
    public :
        Dark
        (
            void
        )
        {
            dbSyncOn   ( );                   // turns on manual screen refreshing
            dbSyncRate ( BASE_FPS );          // sets the FPS rate
            dbDisableEscapeKey ( );           // Disables the escape key exiting the program, so we can do it manualy and clean up leaks
            dbSetImageColorKey ( 255, 0, 255);// Sets the image color key to pink, so that any images with the pink color in them will have that part become transparent
        }

        ~Dark
        (
            void
        )
        {
            
        }
        static double GetFPS()
        {

            return BASE_FPS;
        }

        static int GetFreeSpriteId()
        {
            int Id = 1;

            while (dbSpriteExist(Id))
            {
                Id++;
            }

            return Id;
        }
        
        static int GetMouseX
        (
            void
        )
        {
            return dbMouseX();
        }
        
        static int GetMouseY
        (
            void
        )
        {
            return dbMouseY();
        }
        
        void process
        (
            int (*callback)(void)
        )
        {
            while (LoopGDK())
            {
                if (callback() != 0)
                {
                    break;
                }
                if (dbEscapeKey())
                {
                    break;
                }
                dbSync();
            }
        }
        static int BASE_FPS;
        static double PERIOD;
        static int SIZE_X;
        static int SIZE_Y;
    protected :
};

#endif